home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers2.zip / TAIL.ASM < prev    next >
Assembly Source File  |  1992-01-17  |  10KB  |  382 lines

  1. ;   PC/FTP Packet Driver source, conforming to version 1.05 of the spec
  2. ;   Updated to version 1.08 Feb. 17, 1989.
  3. ;   Copyright 1988-1992 Russell Nelson
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     include    defs.asm
  19.  
  20. code    segment word public
  21.     assume    cs:code, ds:code
  22.  
  23.     extrn    phd_dioa: byte
  24.     extrn    phd_environ: word
  25.     extrn    flagbyte: byte
  26.  
  27.     include    printnum.asm
  28.     include    decout.asm
  29.     include    digout.asm
  30.     include    chrout.asm
  31.  
  32. end_tail_1    label    byte        ; end of the delayed init driver
  33.  
  34. ;usage_msg is of the form "usage: driver [-d -n] <packet_int_no> <args>"
  35.     extrn    usage_msg: byte
  36.  
  37. ;copyright_msg is of the form:
  38. ;"Packet driver for the foobar",CR,LF
  39. ;"Portions Copyright 19xx, J. Random Hacker".
  40.     extrn    copyright_msg: byte
  41.  
  42. copyleft_msg    label    byte
  43.  db "Packet driver skeleton copyright 1988-92, Crynwr Software.",CR,LF
  44.  db "This program is free software; see the file COPYING for details.",CR,LF
  45.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  46.  db CR,LF
  47. crlf_msg    db    CR,LF,'$'
  48.  
  49. no_resident_msg    label    byte
  50.  db CR,LF,"*** Packet driver failed to initialize the board ***",CR,LF,'$'
  51.  
  52. ;parse_args should parse the arguments.
  53. ;called with ds:si -> immediately after the packet_int_no.
  54.     extrn    parse_args: near
  55.  
  56. ;print_parameters should print the arguments.
  57.     extrn    print_parameters: near
  58.  
  59.     extrn    our_isr: near, their_isr: dword
  60.     extrn    packet_int_no: byte
  61.     extrn    is_at: byte, sys_features: byte
  62.     extrn    int_no: byte
  63.     extrn    driver_class: byte
  64.  
  65. location_msg    db    "Packet driver is at segment ",'$'
  66.  
  67. packet_int_no_name    db    "Packet interrupt number ",'$'
  68. eaddr_msg    db    "My Ethernet address is ",'$'
  69. aaddr_msg    db    "My ARCnet address is ",'$'
  70.  
  71. already_msg    db    CR,LF,"There is already a packet driver at ",'$'
  72. int_msg        db    CR,LF
  73.         db    "Error: <int_no> should be between 0 and "
  74. int_msg_num    label    word
  75.         db    "15 inclusive", '$'
  76.  
  77. our_address    db    EADDR_LEN dup(?)
  78.     public    etopen_diagn
  79. etopen_diagn    db    0        ; errorlevel from etopen if set
  80.  
  81. ;etopen should initialize the device.  If it needs to give an error, it
  82. ;can issue the error message and quit to dos.
  83.     extrn    etopen: near
  84.  
  85. ;get the address of the interface.
  86. ;enter with es:di -> place to get the address, cx = size of address buffer.
  87. ;exit with nc, cx = actual size of address, or cy if buffer not big enough.
  88.     extrn    get_address: near
  89.  
  90. already_error:
  91.     mov    dx,offset already_msg
  92.     mov    di,offset packet_int_no
  93.     call    print_number
  94.     mov    ax,4c05h        ; give errorlevel 5
  95.     int    21h
  96.  
  97. usage_error:
  98.     mov    dx,offset usage_msg
  99.     public    error
  100. error:
  101.     mov    ah,9
  102.     int    21h
  103.     mov    ax,4c0ah        ; give errorlevel 10
  104.     int    21h
  105.  
  106.     include    timeout.asm
  107.  
  108.     public    start_1
  109. start_1:
  110.     cld
  111.  
  112.     mov    dx,offset copyright_msg
  113.     mov    ah,9
  114.     int    21h
  115.  
  116.     mov    dx,offset copyleft_msg
  117.     mov    ah,9
  118.     int    21h
  119.  
  120. ;
  121. ; Get the feature byte (if reliable) so we can know if it is a microchannel
  122. ; computer and how many interrupts there are.
  123. ;
  124.     mov    ah,0c0h
  125.     int    15h            ; es:bx <- sys features block
  126.     jc    look_in_ROM        ; error, must use rom.
  127.     or    ah,ah
  128.     jnz    look_in_ROM
  129.     mov    dx,es:[bx]        ; # of feature bytes
  130.     cmp    dx,4            ; do we have the feature byte we want?
  131.     jae    got_features        ;yes.
  132. look_in_ROM:
  133.     mov    dx,0f000h        ;ROM segment
  134.     mov    es,dx
  135.     cmp    byte ptr es:[0fffeh],0fch;is this an AT?
  136.     jne    identified        ;no.
  137.     or    sys_features,TWO_8259    ; ATs have 2nd 8259
  138.     jmp    identified        ; assume no microchannel
  139. got_features:
  140.     mov    ah,es:[bx+2]        ; model byte
  141.     cmp    ah,0fch
  142.     je    at_ps2
  143.     ja    identified        ; FD, FE and FF are not ATs
  144.     cmp    ah,0f8h
  145.     je    at_ps2
  146.     ja    identified        ; F9, FA and FB are not ATs
  147.     cmp    ah,09ah
  148.     jbe    identified        ; old non-AT Compacs go here
  149. at_ps2:                    ; 9B - F8 and FC are assumed to
  150.     mov    ah,es:[bx+5]        ;   have reliable feature byte
  151.     mov    sys_features,ah
  152. identified:
  153.  
  154.     mov    si,offset phd_dioa+1
  155.     call    skip_blanks        ;end of line?
  156.     cmp    al,CR
  157.     je    usage_error_j_1
  158.  
  159. ;print the location we were loaded at.
  160.     mov    dx,offset location_msg
  161.     mov    ah,9
  162.     int    21h
  163.  
  164.     mov    ax,cs            ;print cs as a word.
  165.     call    wordout
  166.  
  167.     mov    dx,offset crlf_msg
  168.     mov    ah,9
  169.     int    21h
  170.  
  171. chk_options:
  172.     call    skip_blanks
  173.     cmp    al,'-'            ; any options?
  174.     jne    no_more_opt
  175.     inc    si            ; skip past option char
  176.     lodsb                ; read next char
  177.     or    al,20h            ; convert to lower case
  178.     cmp    al,'d'
  179.     jne    not_d_opt
  180.     or    flagbyte,D_OPTION
  181.     jmp    chk_options
  182. not_d_opt:
  183.     cmp    al,'n'
  184.     jne    not_n_opt
  185.     or    flagbyte,N_OPTION
  186.     jmp    chk_options
  187. not_n_opt:
  188.     cmp    al,'w'
  189.     jne    not_w_opt
  190.     or    flagbyte,W_OPTION
  191.     jmp    chk_options
  192. not_w_opt:
  193. usage_error_j_1:
  194.     jmp    usage_error
  195. no_more_opt:
  196.  
  197.     mov    di,offset packet_int_no    ;parse the packet interrupt number
  198.     mov    bx,offset packet_int_no_name
  199.     call    get_number        ;  for them.
  200.  
  201.     call    parse_args
  202.     jc    usage_error_j_1
  203.  
  204.     call    skip_blanks        ;end of line?
  205.     cmp    al,CR
  206.     jne    usage_error_j_1
  207.  
  208.     call    verify_packet_int
  209.     jnc    packet_int_ok
  210.     jmp    error
  211. packet_int_ok:
  212.     jne    packet_int_unused
  213.     jmp    already_error        ;give an error if there's one there.
  214. packet_int_unused:
  215.  
  216. ;
  217. ; Verify that the interrupt number they gave is valid.
  218. ;
  219.     cmp    int_no,15        ;can't possibly be > 15.
  220.     ja    int_bad
  221.     test    sys_features,TWO_8259    ; 2nd 8259 ?
  222.     jnz    int_ok            ;yes, no need to check for <= 7.
  223.     mov    int_msg_num,'7'+' '*256    ;correct the error message, just in case.
  224.     cmp    int_no,7        ;make sure that the packet interrupt
  225.     jbe    int_ok            ;  number is in range.
  226. int_bad:
  227.     mov    dx,offset int_msg
  228.     jmp    error
  229. int_ok:
  230.  
  231. ;
  232. ; Map IRQ 2 to IRQ 9 if needed.
  233. ;
  234.     test    sys_features,TWO_8259    ; 2nd 8259 ?
  235.     je    no_mapping_needed    ;no, no mapping needed
  236.     cmp    int_no,2        ;map IRQ 2 to IRQ 9.
  237.     jne    no_mapping_needed
  238.     mov    int_no,9
  239. no_mapping_needed:
  240.  
  241. ; If they chose the -d option, don't call etopen when we are loaded,
  242. ; but when we are called for the first time
  243. ;
  244. ; Save part of the tail, needed by delayed etopen
  245.     test    flagbyte,D_OPTION
  246.     jnz    delayed_open
  247.     call    etopen            ;init the driver.  If any errors,
  248.                     ;this routine returns cy.
  249.     jnc    yes_resident
  250.     jmp    no_resident
  251. delayed_open:
  252.     mov    dx,offset end_tail_1    ; save first part of tail
  253.     push    dx            ;remember where they want to end.
  254.     call    take_packet_int
  255.     jmp    delayed_open_1
  256.  
  257. yes_resident:
  258.     push    dx            ;remember where they want to end.
  259.  
  260.     call    print_parameters    ;echo our parameters.
  261.     or    flagbyte,CALLED_ETOPEN
  262.  
  263.     call    take_packet_int
  264.  
  265.     cmp    driver_class,1        ;Ethernet?
  266.     jne    print_addr_2        ;no, don't print what we don't have.
  267.  
  268.     push    ds
  269.     pop    es
  270.     mov    di,offset our_address
  271.     mov    cx,EADDR_LEN
  272.     call    get_address
  273.  
  274.     mov    dx,offset eaddr_msg
  275.     mov    ah,9
  276.     int    21h
  277.  
  278.     mov    si,offset our_address
  279.     call    print_ether_addr
  280.  
  281.     mov    dx,offset crlf_msg    ;can't depend on DOS to newline for us.
  282.     mov    ah,9
  283.     int    21h
  284.  
  285. print_addr_2:
  286.  
  287.     cmp    driver_class,8        ;ARCnet?
  288.     jne    print_addr_3        ;no, don't print what we don't have.
  289.  
  290.     push    ds
  291.     pop    es
  292.     mov    di,offset our_address
  293.     mov    cx,ARCADDR_LEN
  294.     call    get_address
  295.  
  296.     mov    dx,offset aaddr_msg
  297.     mov    ah,9
  298.     int    21h
  299.  
  300.     mov    al,our_address
  301.     mov    cl,' '            ;Don't eliminate leading zeroes.
  302.     call    byteout
  303.  
  304.     mov    dx,offset crlf_msg    ;can't depend on DOS to newline for us.
  305.     mov    ah,9
  306.     int    21h
  307.  
  308. print_addr_3:
  309. delayed_open_1:
  310.  
  311.     mov    ah,49h            ;free our environment, because
  312.     mov    es,phd_environ        ;  we won't need it.
  313.     int    21h
  314.  
  315.     mov    bx,1            ;get the stdout handle.
  316.     mov    ah,3eh            ;close it in case they redirected it.
  317.     int    21h
  318.  
  319.     pop    dx            ;get their ending address.
  320.     add    dx,0fh            ;round up to next highest paragraph.
  321.     mov    cl,4
  322.     shr    dx,cl
  323.     mov    ah,31h            ;terminate, stay resident.
  324.     mov    al,etopen_diagn        ; errorlevel (0 - 9, just diagnostics)
  325.     int    21h
  326.  
  327. no_resident:
  328.     mov    dx,offset no_resident_msg
  329.     mov    ah,9
  330.     int    21h
  331.  
  332.     mov    ax,4c00h + 32        ; give errorlevel 32
  333.     cmp    al,etopen_diagn
  334.     ja    no_et_diagn        ; etopen gave specific reason?
  335.     mov    al,etopen_diagn        ; yes, use that for error level
  336. no_et_diagn:
  337.     int    21h
  338.  
  339. ;             Suggested errorlevels:
  340. ;
  341. ; _____________________  0 = normal
  342. ;              1 = unsuitable memory address given; corrected
  343. ; In most cases every-     2 = unsuitable IRQ level given; corrected
  344. ; thing should work as     3 = unsuitable DMA channel given; corrected
  345. ; expected for lev 1-5     4 = unsuitable IO addr given; corrected (only 1 card)
  346. ; _____________________     5 = packet driver for this int # already loaded
  347. ; External errors, when    20 = general cable failure (but pkt driver is loaded)
  348. ; corrected normal    21 = network cable is open             -"-
  349. ; operation starts    22 = network cable is shorted          -"-
  350. ; _____________________ 23 = 
  351. ; Packet driver not    30 = usage message
  352. ; loaded. A new load    31 = arguments out of range
  353. ; attempt must be done    32 = unspecified device initialization error
  354. ;            33 = 
  355. ;            34 = suggested memory already occupied
  356. ;            35 = suggested IRQ already occupied
  357. ;            36 = suggested DMA channel already occupied
  358. ;            37 = could not find the network card at this IO address
  359.  
  360.  
  361. take_packet_int:
  362.     mov    ah,35h            ;remember their packet interrupt.
  363.     mov    al,packet_int_no
  364.     int    21h
  365.     mov    their_isr.offs,bx
  366.     mov    their_isr.segm,es
  367.  
  368.     mov    ah,25h            ;install our packet interrupt
  369.     mov    dx,offset our_isr
  370.     int    21h
  371.     ret
  372.  
  373.     include    verifypi.asm
  374.     include    getnum.asm
  375.     include    getdig.asm
  376.     include    skipblk.asm
  377.     include    printea.asm
  378.  
  379. code    ends
  380.  
  381.     end
  382.